package vn.edu.saigontech.ncms.web.offering;

import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.util.DateUtil;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateNextOfferingAction extends AbstractValidator {
	
	private String startDate;
	private String endDate;
	
	public String check() {
		if(!Checker.isEmpty(this.startDate)) {
			if(!Checker.isDate(this.startDate, this.i18n("format.date"))) {
				this.sendKeyError("validator.mask", "startDate", "format.date");
			}
		}
		if(!Checker.isEmpty(this.endDate)) {
			if(!Checker.isDate(this.endDate, this.i18n("format.date"))) {
				this.sendKeyError("validator.mask", "endDate", "format.date");
			}
		}
		if(!Checker.isEmpty(this.startDate) && !Checker.isEmpty(this.endDate)) {
			if(DateUtil.fromString(this.startDate, this.i18n("format.date")).after(DateUtil.fromString(this.endDate, this.i18n("format.date")))) {
				this.sendKeyError("validator.greater", "endDate", "startDate");
			}
		}
		return this.toSuccess();
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}
}
